package demo1;

import org.springframework.context.annotation.AnnotationConfigApplicationContext;

public class Demo {
    public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
//      直接new对象 简单明了 写死了
        Person person = new Person();
        person.sayHello();
//       反射调用 灵活改变对象仅需改获取对象的代码但需要写大量代码
        Class cl = Class.forName("demo1.Person");
        Person person1 = (Person) cl.newInstance();
        person1.sayHello();
//        Spring容器管理
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext("demo1");
        Person p2 = context.getBean(Person.class);
        p2.sayHello();
    }
}
